<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<title></title>
		<script type="text/javascript" src="../script/api.js"></script>
		<script type="text/javascript" src="../script/jquery.js"></script>
		<style>
			table {
				margin-left: 5px;
				margin-right: 5px;
				width: calc(100% - 10px);
				text-align: center;
				border: 0px;
				font: caption;
			}
			table tr {
				border: 1px solid #f4f4f4;
				padding: 5px;
			}
			table tr td {
				width: 32%;
				border: 1px solid #f4f4f4;
				padding: 5px
			}
			.tr1 {
				background-color: #f4f4f4;
			}
			.one {
				width: 100%;
				border-bottom: 1px solid #eee;
				padding: 5px;
			}
			.one_zi {
				margin-left: 10px;
				margin-top: 5px;
				font-size: 12px;
			}
			body {
				background: #FFF;
			}
		</style>
	</head>
	<body >
		<div id="device_div">
			A0:E6:F8:4E:9C:28 ======>>><span id="k_head"> 未匹配 </span>
		</div>
		<div id="device_uuid"></div>
		<div id="device_data"></div>
		<input type="button" class='aui-btn aui-btn-info aui-btn-block' tapmode onclick="scanDevice()" value="搜索设备"/>
		<input type="button" class='aui-btn aui-btn-info aui-btn-block' tapmode onclick="connectedDevice()" value="连接"/>
		<input type="button" class='aui-btn aui-btn-info aui-btn-block' tapmode onclick="startNotifyDevice()" value="开始采集数据"/>
		<input type="button" class='aui-btn aui-btn-info aui-btn-block' tapmode onclick="stopNotifyDevice()" value="获取数据"/>
		<div style=" padding:10px 0px;color:#9d9d9d;display:none;" id="qximg">
			<span style="margin-left: 10px;">步态数据列表及图像</span>
		</div>
		<script>
			var scanDeviceModule = null;
			apiready = function() {
				api.parseTapmode();
				$("#device_data").hide();
				scanDeviceModule = api.require('scanDeviceModule');
			}
			var uuid = null;
			head = 'A0:E6:F8:4E:9C:28'//'A0:E6:F8:4E:9C:28';
			var cur_param = {
				devices : [{
					title : "测试设备",
					addr : head,
					id : "head"
				}]
			};
			function scanDevice() {
				scanDeviceModule.scan(function(ret, err) {
					if (ret.status == 0) {
						if (ret.addr == head) {
							$("#k_head").html('<span style="color:#f4c300">已匹配</span>')
						}
					} else {
						alert(ret.msg);
					}
				});
			}

			function stopDevice() {
				alert("停止查询设备");
				scanDeviceModule.stop(function(ret, err) {
					alert("设备停止");
				});
			}

			function show(idx) {
				$('.all').hide();
				$('.div' + idx).show();
				$("#device_data").show();
			}

			function connectedDevice() {
				var param = {};	//cur_param.showToast=true;
				scanDeviceModule.connect(cur_param, function(ret, err) {
					if (ret.status == 0) {
						if (ret.addr == head) {
							$("#k_head").html('<span style="color:green;">已连接</span>')
						}
					} else {
						alert(JSON.stringify(ret));
					}
				});
			}

			function disConnectedDevice() {
				var param = {
					device_address : "xxx"
				};
				scanDeviceModule.connectedDevice(param, function(ret, err) {
					if (ret.isConnected == 3) {
						if (ret.addr == head) {
							$("#k_head").html('未匹配')
						}
					}
				});
			}

			function readDevice(s_uuid, c_uuid) {
				sysAlert("读取设备信息");
				var param = {
					device_name : "测试设备",
					device_address : uuid,
					service_uuid : s_uuid,
					characteristic_uuid : c_uuid
				};
				scanDeviceModule.readDevice(param, function(ret, err) {
					alert(JSON.stringify(ret));
				});
			}

			var service_uuid = null;
			var characteristic_uuid = null;
			function startNotifyDevice() {
				alert("开始采集数据");
				var param = {
					uuid : "0000FFF0-0000-1000-8000-00805F9B34FB",
					charUuid : "0000fff1-0000-1000-8000-00805f9b34fb"
				};
				scanDeviceModule.notify(param, function(ret, err) {
					console.log(JSON.stringify(ret));
				});
			}

			var tt;
			function stopNotifyDevice() {
				alert("停止数据采集，获取数据");
				var param = {
					uuid : "0000FFF0-0000-1000-8000-00805F9B34FB",
					charUuid : "0000fff1-0000-1000-8000-00805f9b34fb"
				};
				scanDeviceModule.stopNotify(param, function(ret, err) {
	alert(JSON.stringify(ret));
				});
			}

			function backMe() {
				api.closeWin();
			}

			function fangda() {
				api.openWin({
					name : 'qximg',
					url : 'widget://html/qximg.html',
					slidBackEnabled : false,
					pageParam : {
						ret : tt,
						isHead : true
					},
					bgColor : '#000'
				});
			}

			function loadQxImg() {
				var htm = "";
				htm += "<div class=\"wdbll4\" align = \"center\" id=\"container\" ></div >"
				$("#qximg").show();
				$("#qximg").append(htm);
				$("#container").css({
					width : api.frameWidth,
					height : 200
				})
				$("#container").highcharts({
					//去掉highcharts 默认的标题
					title : {
						text : ''
					},
					chart : {
						zoomType : 'x'
					},
					//去掉highcharts 自带的网站标识
					//								credits : {
					//									enabled : false
					//								},
					credits : {
						text : '<<点击放大！',
						href : "javascript:fangda()",
						style : {
							cursor : 'pointer',
							color : '#909090',
							fontSize : '18px',
						},
						position : {
							align : 'right',
							x : -10,
							verticalAlign : 'bottom',
							y : -5
						}
					},
					//去掉下载打印按钮
					exporting : {
						enabled : false
					},
					xAxis : {
						categories : tt.xAxis
					},
					//去掉左边悬浮标题
					yAxis : {
						title : {
							text : ''
						},
					},
					series : [{
						name : 'x',
						data : tt.yAxis[0]
					}, {
						name : 'y',
						data : tt.yAxis[1]
					}, {
						name : 'z',
						data : tt.yAxis[2]
					}]
				});
			}
		</script>
	</body>
</html>
